home *** CD-ROM | disk | FTP | other *** search
-
-
-
- MALLOC C Library Procedures MALLOC
-
-
-
- NNAAMMEE
- malloc, free, realloc, calloc, alloca - memory allocator
-
- SSYYNNOOPPSSIISS
- #include <stdlib.h>
-
- cchhaarr **mmaalllloocc((ssiizzee))
- uunnssiiggnneedd ssiizzee;;
-
- ffrreeee((ppttrr))
- cchhaarr **ppttrr;;
-
- cchhaarr **rreeaalllloocc((ppttrr,, ssiizzee))
- cchhaarr **ppttrr;;
- uunnssiiggnneedd ssiizzee;;
-
- cchhaarr **ccaalllloocc((nneelleemm,, eellssiizzee))
- uunnssiiggnneedd nneelleemm,, eellssiizzee;;
-
- cchhaarr **aallllooccaa((ssiizzee))
- iinntt ssiizzee;;
-
- DDEESSCCRRIIPPTTIIOONN
- _M_a_l_l_o_c and _f_r_e_e provide a general-purpose memory allocation
- package. _M_a_l_l_o_c returns a pointer to a block of at least
- _s_i_z_e bytes beginning on a word boundary.
-
- The argument to _f_r_e_e is a pointer to a block previously
- allocated by _m_a_l_l_o_c; this space is made available for
- further allocation, but its contents are left undisturbed.
-
- Needless to say, grave disorder will result if the space
- assigned by _m_a_l_l_o_c is overrun or if some random number is
- handed to _f_r_e_e.
-
- _M_a_l_l_o_c maintains multiple lists of free blocks according to
- size, allocating space from the appropriate list. It calls
- _s_b_r_k (see _b_r_k(2)) to get more memory from the system when
- there is no suitable space already free.
-
- _R_e_a_l_l_o_c changes the size of the block pointed to by _p_t_r to
- _s_i_z_e bytes and returns a pointer to the (possibly moved)
- block. The contents will be unchanged up to the lesser of
- the new and old sizes. The Sprite version of _r_e_a_l_l_o_c
- differs from other UNIX versions in that _p_t_r may not point
- to a free block (in other UNIX versions _p_t_r _m_a_y _p_o_i_n _t_o _a
- _b_l_o_c_k _f_r_e_e_d _s_i_n_c_e _t_h_e _l_a_s_t _c_a_l_l _t_o _m_a_l_l_o_c, _c_a_l_l_o_c, or _r_e_a_l_-
- _l_o_c).
-
- _C_a_l_l_o_c allocates space for an array of _n_e_l_e_m elements of
- size _e_l_s_i_z_e. The space is initialized to zeros.
-
-
-
-
- Sprite v1.0 May 14, 1986 1
-
-
-
-
-
-
- MALLOC C Library Procedures MALLOC
-
-
-
- _A_l_l_o_c_a allocates _s_i_z_e bytes of space in the stack frame of
- the caller. This temporary space is automatically freed on
- return.
-
- Each of the allocation routines returns a pointer to space
- suitably aligned (after possible pointer coercion) for
- storage of any type of object.
-
- SSEEEE AALLSSOO
- brk(2), pagesize(2)
-
- DDIIAAGGNNOOSSTTIICCSS
- _M_a_l_l_o_c, _r_e_a_l_l_o_c and _c_a_l_l_o_c return a null pointer (0) if
- there is no available memory or if the arena has been
- detectably corrupted by storing outside the bounds of a
- block. _M_a_l_l_o_c may be recompiled to check the arena very
- stringently on every transaction; those sites with a source
- code license may check the source code to see how this can
- be done.
-
- BBUUGGSS
- When _r_e_a_l_l_o_c returns 0, the block pointed to by _p_t_r may be
- destroyed.
-
- The current implementation of _m_a_l_l_o_c does not always fail
- gracefully when system memory limits are approached. It may
- fail to allocate memory when larger free blocks could be
- broken up, or when limits are exceeded because the size is
- rounded up. It is optimized for sizes that are powers of
- two.
-
- _A_l_l_o_c_a is machine dependent; its use is discouraged.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sprite v1.0 May 14, 1986 2
-
-
-
-